package cn.xuchunh.campusbbs.utils;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import cn.xuchunh.campusbbs.AppContext;

/**
 * Created by XuChunH on 2015/8/31.
 */
public class DeviceUtil {

    public static String getIMEI() {
        TelephonyManager telephonyManager = (TelephonyManager) AppContext.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getDeviceId();
    }

    public static String getIMSI() {
        TelephonyManager telephonyManager = (TelephonyManager) AppContext.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
        String imsi = telephonyManager.getSubscriberId();
        return TextUtils.isEmpty(imsi) ? "" : imsi;
    }

    public static int getScreenWidth(Context context) {
        DisplayMetrics metrics = new DisplayMetrics();
        Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        display.getMetrics(metrics);
        return metrics.widthPixels;
    }

    public static int getScreenWidth() {
        return getScreenWidth(AppContext.getInstance());
    }

    public static float getTextSizePixel(float scaledSize, Context context) {
        DisplayMetrics metrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
        return scaledSize * metrics.scaledDensity;
    }

    public static float getTextSizePixel(float scaledSize) {
        return getTextSizePixel(scaledSize, AppContext.getInstance());
    }

    public static int getTextSizePixelOffset(float scaledSize) {
        return (int) getTextSizePixel(scaledSize);
    }

}
